<template>
  <div class="cm-transaction-list bg-c-fff right-height mb70">
    <div class="bread rel">
      <a href="javascript:void(0);" class="font-s-16">首席监控师-交易监控订单管理</a>
      <form action="" class="abs seach">
        <input type="text" class="input-css" placeholder="发起人/监控师/监控员" v-model="keyWord">
        <button type="button" class="xl-btn-css blue-button vb" @click="getData(1)">搜索</button>
        <a href="#/index/cm-transaction-reallocate" class="blue-button vb">分配记录</a>
      </form>
    </div>
    <div class="content">
      <choose-type typename="订单状态" valuename="orderType" :itemlist="orderlist" :active="orderActive" @typechanged="onOptionChanged"></choose-type>
      <choose-type typename="交易阶段" valuename="transType" :itemlist="translist" :active="transActive" @typechanged="onOptionChanged"></choose-type>
      <choose-type typename="监控类型" valuename="typeType" :itemlist="typelist" :active="typeActive" @typechanged="onOptionChanged"></choose-type>
      <table width="100%" class="auto">
        <tr>
          <th>订单时间</th>
          <th>订单编号</th>
          <th>发起人</th>
          <th>监控类型</th>
          <th>交易阶段</th>
          <th>订单状态</th>
          <th>监控师</th>
          <th>监控员</th>
          <th>操作</th>
        </tr>
        <tr v-for="item in list">
          <td>{{item.createTime}}</td>
          <td>{{item.id}}</td>
          <td>{{item.businessName}}</td>
          <td>{{item.monitorType | monitorTypeFilter}}</td>
          <td>{{item.status | statusFilter}}</td>
          <td>{{item.stage | stageFilter}}</td>
          <td>{{item.monitorName | nameFilter}}</td>
          <td>{{item.workerName | nameFilter}}</td>
          <td>
            <button class="blue-button small-btn-css" @click="onDetailsClick(item.id,item.status)">查看详情</button>
            <button class="blue-button small-btn-css" @click="reset(item.id, item.stage)">重新分配</button>
          </td>
        </tr>
      </table>
      <div class="fix foot-box">
        <div class="no-data-tip" v-show="list.length===0">暂无相关数据</div>
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.list!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
    <vodal :show="resetShow" animation="zoom" :width="400" :height="390" @hide="resetShow=false">
      <form @submit.prevent="onReastSubmit">
        <div class="vodal-main">
          <h4>重新分配订单</h4>
          <div class="con">
            <p><span>所属角色：</span>
              <select v-model="roleValue" @change="changeRole(roleValue)">
                <option value="">监控师/监控员</option>
                <option :value="1">交易监控师</option>
                <option :value="2">交易监控员</option>
              </select>
            </p>
            <p><span>重新分配给：</span>
              <select v-model="nameId">
                <option value="">角色列表</option>
                <option v-for="item in nameList" :value="item.id">{{item.account}}</option>
              </select>
            </p>
            <P>
              <span>备注:</span>
              <textarea class="vt" v-model="text"></textarea>
            </P>
          </div>
          <div class="btn-box auto tc">
            <button type="submit" class="blue-button xl-btn-css">确认</button>
            <button type="button" class="blue-button xl-btn-css" @click="cancel">取消</button>
          </div>
        </div>
      </form>
    </vodal>
  </div>
</template>
<script type="text/javascript">
import Pagination from '../components/Pagination'
import ChooseType from '../components/ChooseType'
export default {
  components: {
    Pagination,
    ChooseType
  },
  data() {
    return {
      pageIndex: 1,
      pageTotal: 0,
      resetShow: false,
      orderActive: '',
      orderlist: [{
        value: '',
        text: '全部'
      }, {
        value: '0',
        text: '待分配'
      }, {
        value: '1',
        text: '进行中'
      }, {
        value: '3',
        text: '已终止'
      }, {
        value: '2',
        text: '已完成'
      }],
      transActive: '',
      translist: [{
        value: '',
        text: '全部'
      }, {
        value: '2',
        text: '查看资质报告'
      }, {
        value: '3',
        text: '合同审查'
      }, {
        value: '4',
        text: '监控师绘图'
      }, {
        value: '5',
        text: '监控员交易监控'
      }],
      typeActive: '',
      typelist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '单方监控'
      }, {
        value: '2',
        text: '双方监控'
      }, {
        value: '3',
        text: '多方监控'
      }],
      list: [],
      orderId: '',
      roleValue: '',
      nameId: '',
      nameList: [],
      keyWord: '',
      text: ''
    }
  },
  mounted() {
    this.onPageChange(1)
  },
  methods: {
    onOptionChanged(type, value) {
      if (type === 'orderType') {
        this.orderActive = value
      }
      if (type === 'transType') {
        this.transActive = value
      }
      if (type === 'typeType') {
        this.typeActive = value
      }
      this.getData(1)
    },
    onPageChange(n) {
      this.getData(n)
    },
    getData(n) {
      this.$http.get('/transactionMonitorSer/chief/read/list', {
        params: {
          status: this.transActive,
          stage: this.orderActive,
          monitorType: this.typeActive,
          page: n,
          rows: 10,
          keyWord: this.keyWord
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.list = data.data.rows
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    reset(id, stage) {
      if (stage === 2) {
        this.$toasted.show('订单已完成！')
        return
      }
      if (stage === 3) {
        this.$toasted.show('订单已终止！')
        return
      }
      this.resetShow = true
      this.orderId = id
    },
    changeRole(value) {
      this.$http.get('/transactionMonitorSer/queryUsers', {
        params: {
          type: value
        }
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.nameList = data.data.rows
          console.log(this.nameList)
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onReastSubmit() {
      if (!this.roleValue) {
        this.$toasted.show('请选择所属角色')
        return
      }
      if (!this.nameId) {
        this.$toasted.show('请选择重新分配的角色姓名')
        return
      }
      this.$http.post('/transactionMonitorSer/chief/changeRole', {
        id: this.orderId,
        roleType: this.roleValue,
        sysUserId: this.nameId

      }).then(data => {
        if (data.data.httpCode === 200) {
          this.$toasted.show('修改成功')
          this.resetShow = false
          this.getData(this.pageIndex)
          this.cancel()
        } else {
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
        this.$toasted.show('网络出错')
      })
    },
    onDetailsClick(id, status) {
      if (status === 2) {
        this.$router.push('/cm-transaction-aptitude?type=chief&id=' + id)
      }
      if (status === 3) {
        this.$router.push('/cm-transaction-contract?type=chief&id=' + id)
      }
      if (status === 4) {
        this.$router.push('/cm-transaction-drawing?type=chief&id=' + id)
      }
      if (status >= 5) {
        this.$router.push('/cm-transaction-flow?type=chief&id=' + id)
      }
    },
    cancel() {
      this.resetShow = false
      this.roleValue = ''
      this.nameId = ''
      this.text = ''
    }
  },
  filters: {
    monitorTypeFilter(m) {
      if (m === 1) {
        return '单方监控'
      } else if (m === 2) {
        return '双方监控'
      } else if (m === 3) {
        return '多方监控'
      }
    },
    statusFilter(m) {
      if (m === 2) {
        return '查看资质报告'
      } else if (m === 3) {
        return '合同审查'
      } else if (m === 4) {
        return '监控师绘图'
      } else if (m >= 5) {
        return '监控员交易监控'
      }
    },
    stageFilter(m) {
      if (m === 0) {
        return '待分配'
      } else if (m === 1) {
        return '进行中'
      } else if (m === 2) {
        return '已完成'
      } else if (m === 3) {
        return '已终止'
      }
    },
    nameFilter(n) {
      if (!n) {
        return '--'
      } else {
        return n
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.bread {
  padding-left: 20px;
  height: 50px;
  border-bottom: 1px solid #ddd;
}

.bread a {
  line-height: 50px;
}

.seach a {
  color: #fff;
  font-size: 14px;
  width: 100px;
  height: 35px;
  line-height: 35px;
}

.cm-transaction-list .seach {
  right: 10px;
  top: 8px;
}

.cm-transaction-list .seach input,
.cm-transaction-list .seach button {
  height: 35px;
  line-height: 35px;
}

.content {
  margin-top: 10px;
  padding: 0 30px;
}

.content table {
  margin-top: 20px;
}

.content table td button:nth-of-type(1) {
  margin-bottom: 7px;
}


.foot-box {
  padding: 35px 32px 15px 13px;
}

.pagination {
  width: auto!important;
  margin: 0 auto!important;
}

.vodal-main .con {
  padding: 4px 13px;
}

.vodal-main .con p {
  margin-bottom: 15px;
}

.vodal-main .con p span {
  width: 94px;
  display: inline-block;
  text-align: right;
}

.vodal-main .con p textarea {
  width: 235px;
  height: 100px;
}

select {
  width: 110px;
  height: 35px;
  border: 1px solid #ddd;
}

</style>
